/*=====================================================================================================================
                    Copyright(c) 2005 Geometric PLM Software Corp. All rights reserved.
                             Unpublished - All rights reserved
=======================================================================================================================
File description:
    Filename: file_utils.h
    Module  : Common module.

        This file includes some operations of the file.

=======================================================================================================================
Date               Name              Description of Change
23-Jul-2009        Jerry,Wu          Initialize creation
$HISTORY$
=====================================================================================================================*/
#ifndef FILE_UTILS_H
#define FILE_UTILS_H

#include "stdio.h"
#include "unidefs.h"

#ifdef __cplusplus
    extern "C"
    {
#endif
/**
 * ATTENTION: 
 *      It may be different when other company's project, 
 *      so please change the TC_TMP_DIR MARCO.
 *
 */
#define TC_TMP_DIR              "TC_TMP_DIR"

    /**
    * Open(Create) the file with the composite rules and user id.
    * @param funName   - <I> The func name of the file.
    * @param welcome   - <I> The welcome infomation.
    * @param filePath  - <OF> The new path
    * @param file      - <O> FILE pointer(need close)
    * @return - ITK_OK or Error code
    */
    extern int FILE_def_open( const char *funName, const char *postfix, const char *welcome, char **filePath, FILE **file );

    /**
    * Open(Create) the file with the composite rules.
    * @param funName   - <I> The func name of the file.
    * @param desc      - <I> The middle description for file
    * @param welcome   - <I> The welcome infomation.
    * @param filePath  - <OF> The new path
    * @param file      - <O> FILE pointer(need close)
    *
    *     All the file will create in $TC_TMP_DIR sys enviroment, and the file name will be like the following
    *          $TEMP\#funName#userId#systime  ( all )
    *          $TEMP\#funName#systime         ( without #des)
    *          $TEMP\#des#systime          ( without #funName)
    * @return - ITK_OK or Error code
    */
    extern int FILE_open( const char *funName, const char *desc, const char *postfix, const char *welcome, char **filePath, FILE **file );

    /**
    * Close the log file.
    * @param    f        - <I> The file pointer
    * @return - N/A
    */
    extern void FILE_close( FILE **f );

    /**
    * read a line of a file.
    * @param file - <I> the pointer to a FILE handler
    * @param line - <OF>  the pointer to a string to store the line
    * @return - the length of the line, return EOF if end of the file
    */
    extern int FILE_getLine(FILE* file, char** line);


    /**
    * Gets the content of one line.
    * @param file  - <I> FILE handler
    * @param value - <O> the returned value
    * @param maxLength - <I> the max length to 
    * @return - the count in value.
    */    
    extern int FILE_getLine_max( FILE *file, char value[], int maxLength );

    /**
    * copy file
    * @param srcFilePath  - <I> source file to be copied
    * @param dstFilePath  - <I> dest file
    * @return - true if copy sucessfully
    **/
    extern logical FILE_copy_file(const char* srcFilePath, const char* dstFilePath);

#ifdef __cplusplus
    }
#endif

#define MEDIUM_FILE_create( ppath, pfile ) FILE_def_open( __FUNCTION__, ".mdf", NULL, (ppath), (pfile) )

#endif //FILE_UTILS_H
